package com.zuocheng.librarycar;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zuocheng.librarycar.R;


public class OverAllTitleBar extends RelativeLayout {

    public TextView     tvTitle;
    public TextView     tvBar;
    public TextView     tvLocation;
    public TextView     tvRightText;
    public TextView tvRightText2;

    public ImageView    ivBack;
    public ImageView    ivMessage;

    public LinearLayout llLocation;

    public Context context;
    public LinearLayout llRoot;

    public OverAllTitleBar(Context context) {
        this(context,null);
    }

    public OverAllTitleBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public OverAllTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        View root = LayoutInflater.from(context).inflate(R.layout.view_layout_over_all_title_bar, null);
        addView(root);
        init();
        initBar();
    }

    private void initBar() {
        ViewGroup.LayoutParams layoutParams = tvBar.getLayoutParams();
        layoutParams.height = getStatusBarHeight(context);
        tvBar.setLayoutParams(layoutParams);
    }

    private int getStatusBarHeight(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    public void init() {
        tvTitle     = findViewById(R.id.tv_title);
        tvBar       = findViewById(R.id.tv_bar);
        tvLocation  = findViewById(R.id.tv_location);
        llLocation  = findViewById(R.id.ll_location);
        ivBack      = findViewById(R.id.iv_back);
        ivMessage   = findViewById(R.id.iv_message);
        tvRightText = findViewById(R.id.tv_right_text);
        tvRightText2 = findViewById(R.id.tv_right_text2);
        llRoot = findViewById(R.id.ll_root);
    }

    public void showLocation() {
        llLocation.setVisibility(View.VISIBLE);
        ivBack.setVisibility(View.GONE);
    }

    public void showBack() {
        llLocation.setVisibility(View.GONE);
        ivBack.setVisibility(View.VISIBLE);
    }
}
